package com.zzyl.framework.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author mr.zhao
 * @Date 2025/5/20 14:57
 */
@Component
public class AiInvoker {

	@Value("${qianfan.temperature}")
	private String temperature;

	@Value("${qianfan.model}")
	private String model;

	public String invokeQianFanChat(String prompt){
		ChatResponse response = new Qianfan().chatCompletion()
				.model(model)
				.addMessage("user", prompt) //添加用户消息(此方法可以调用多次,以实现多轮对话的消息传递)
				.temperature(Double.valueOf(temperature)) //自定义超参数
				.responseFormat("json_object") //指定Result结果为JSON
				.execute();//发起请求
		return response.getResult();
	}
}
